package demo.guiJFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class GameELSFK {
    private JFrame frame;
    private JPanel panel;
    private int[][] num;
    private FK[] fk;
    private boolean hasMove = false;
    private Gra g = null;

    class Gra extends Thread {
        int a = 1;

        void quit() {
            a = 0;
        }

        public void run() {
            while (a == 1) {
                try {
                    if (canDown()) {
                        goDown();
                        Thread.sleep(800);
                    } else {
                        if (canLeft() || canRight()) {
                            Thread.sleep(800);
                            if (!hasMove) {
                                this.quit();
                                g = new Gra();
                                g.start();
                            }
                        } else {
                            this.quit();
                            g = new Gra();
                            g.start();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }
    }

    public static void main(String[] args) {
        new GameELSFK();
    }

    private GameELSFK() {
        setNum();
        frame = new JFrame("����˹����");
        frame.setBounds(785, 250, 350, 595);
        frame.setLayout(new BorderLayout());
        panel = new JPanel();
        panel.setSize(350, 595);
        panel.setLayout(new GridLayout(17, 10, 1, 1));
        fk = new FK[170];
        for (int i = 0; i < 170; i++) {
            fk[i] = new FK(num[i / 17][i % 10]);
            panel.add(fk[i].ret());
        }
        addLis();
        frame.add(panel, BorderLayout.CENTER);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        panel.requestFocus();
        g = new Gra();
        g.start();
    }

    private void addLis() {
        panel.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {

            }
        });
    }

    private void setNum() {
        num = new int[17][10];
        for (int i = 0; i < 17; i++)
            for (int j = 0; j < 10; j++) {
                num[i][j] = 0;
            }
    }

    private void goDown() {

    }

    private boolean canDown() {
        return true;
    }

    private boolean canLeft() {
        return true;
    }

    private boolean canRight() {
        return true;
    }
}

class DFK {
    int[][] num = new int[2][4];

    public DFK(int a) {
        switch (a) {
            case 0:
        }
    }
}

class FK {
    private JLabel lab;

    FK(int a) {
        lab = new JLabel();
        lab.setBorder(BorderFactory.createLineBorder(Color.black));
        lab.setOpaque(true);
        set(a);
    }

    JLabel ret() {
        return lab;
    }

    public void set(int a) {
        switch (a) {
            case 0:
                lab.setBackground(Color.WHITE);
                break;
            case 1:
                lab.setBackground(new Color(160, 160, 160));
                break;
            case 2:
                lab.setBackground(new Color(36, 155, 179));
                break;
            default:
                lab.setBackground(new Color(237, 207, 0));
        }
    }
}
